import java.awt.Color;
import java.awt.Dialog;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GraphicsConfiguration;
import java.awt.Window;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.Connection;
import java.util.ArrayList;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.UIManager;

import org.dyno.visual.swing.layouts.Constraints;
import org.dyno.visual.swing.layouts.GroupLayout;
import org.dyno.visual.swing.layouts.Leading;

import Utiles.convertidor;
import beans.b_amo;
import beans.b_mascota;
import beans.b_respuesta;
import datos.conexion;
import datos.d_amo;
import datos.d_mascota;


//VS4E -- DO NOT REMOVE THIS LINE!
public class ingreso_mascota extends JDialog {

	private static final long serialVersionUID = 1L;
	private b_amo amo;
	private JLabel jLabel0;
	private JLabel jLabel3;
	private JLabel jLabel2;
	private JLabel jLabel1;
	private JTextField jTextField0;
	private JComboBox jComboBox0;
	private JComboBox jComboBox1;
	private JTextField jTextField1;
	private JButton jButton0;
	private JLabel jLabel4;
	private JComboBox jComboBox2;
	private static final String PREFERRED_LOOK_AND_FEEL = "javax.swing.plaf.metal.MetalLookAndFeel";
	public ingreso_mascota(Window parent) {
		super(parent);
		initComponents();
	}

	public ingreso_mascota(Dialog parent, String title, boolean modal,
			GraphicsConfiguration arg) {
		super(parent, title, modal, arg);
		initComponents();
	}

	public ingreso_mascota(Dialog parent, String title, boolean modal) {
		super(parent, title, modal);
		initComponents();
	}

	public ingreso_mascota(Dialog parent, String title) {
		super(parent, title);
		initComponents();
	}

	public ingreso_mascota(Window parent, String title,
			ModalityType modalityType, GraphicsConfiguration arg) {
		super(parent, title, modalityType, arg);
		initComponents();
	}

	public ingreso_mascota(Window parent, String title,
			ModalityType modalityType) {
		super(parent, title, modalityType);
		initComponents();
	}

	public ingreso_mascota(Window parent, String title) {
		super(parent, title);
		initComponents();
	}

	public ingreso_mascota(Window parent, ModalityType modalityType) {
		super(parent, modalityType);
		initComponents();
	}

	public ingreso_mascota(Frame parent, String title) {
		super(parent, title);
		initComponents();
	}

	public ingreso_mascota(Frame parent, boolean modal) {
		super(parent, modal);
		initComponents();
	}

	public ingreso_mascota(Frame parent) {
		super(parent);
		initComponents();
	}

	public ingreso_mascota( b_amo a ) {
		this.amo = a;
		initComponents();
	}

	public ingreso_mascota(Dialog parent, boolean modal) {
		super(parent, modal);
		initComponents();
	}

	public ingreso_mascota(Dialog parent) {
		super(parent);
		initComponents();
	}

	public ingreso_mascota(Frame parent, String title, boolean modal,
			GraphicsConfiguration arg) {
		super(parent, title, modal, arg);
		initComponents();
	}

	public ingreso_mascota(Frame parent, String title, boolean modal) {
		super(parent, title, modal);
		initComponents();
	}

	private void initComponents() {
		setFont(new Font("Dialog", Font.PLAIN, 12));
		setBackground(Color.white);
		setForeground(Color.black);
		setLayout(new GroupLayout());
		add(getJLabel0(), new Constraints(new Leading(12, 12, 12), new Leading(12, 12, 12)));
		add(getJTextField0(), new Constraints(new Leading(75, 100, 10, 10), new Leading(12, 12, 12)));
		add(getJComboBox0(), new Constraints(new Leading(75, 96, 10, 10), new Leading(34, 12, 12)));
		add(getJComboBox1(), new Constraints(new Leading(75, 96, 12, 12), new Leading(62, 12, 12)));
		add(getJButton0(), new Constraints(new Leading(113, 10, 10), new Leading(173, 10, 10)));
		add(getJLabel4(), new Constraints(new Leading(12, 12, 12), new Leading(96, 12, 12)));
		add(getJLabel3(), new Constraints(new Leading(12, 12, 12), new Leading(65, 12, 12)));
		add(getJLabel1(), new Constraints(new Leading(12, 44, 12, 12), new Leading(40, 12, 12)));
		add(getJComboBox2(), new Constraints(new Leading(75, 12, 12), new Leading(90, 12, 12)));
		add(getJTextField1(), new Constraints(new Leading(75, 39, 12, 12), new Leading(127, 12, 12)));
		add(getJLabel2(), new Constraints(new Leading(12, 12, 12), new Leading(127, 12, 12)));
		setSize(320, 240);
	}

	private JComboBox getJComboBox2() {
		if (jComboBox2 == null) {
			jComboBox2 = new JComboBox();
			jComboBox2.setModel(new DefaultComboBoxModel(new Object[] { "Macho", "Hembra" }));
			jComboBox2.setDoubleBuffered(false);
			jComboBox2.setBorder(null);
		}
		return jComboBox2;
	}

	private JLabel getJLabel4() {
		if (jLabel4 == null) {
			jLabel4 = new JLabel();
			jLabel4.setText("Sexo");
		}
		return jLabel4;
	}

	private JButton getJButton0() {
		if (jButton0 == null) {
			jButton0 = new JButton();
			jButton0.setText("Guardar " + amo.getRut() );
			jButton0.addMouseListener(new MouseAdapter() {
	
				public void mouseClicked(MouseEvent event) {
					jButton0MouseMouseClicked(event);
				}
			});
		}
		return jButton0;
	}

	private JTextField getJTextField1() {
		if (jTextField1 == null) {
			jTextField1 = new JTextField();
		}
		return jTextField1;
	}

	private JComboBox getJComboBox1() {
		if (jComboBox1 == null) {
			jComboBox1 = new JComboBox();
			jComboBox1.setModel(new DefaultComboBoxModel(new Object[] {}));
			///////////////////////////////////
			
			jComboBox1.setEnabled(true);
			jComboBox1.removeAllItems();
			
			conexion con = new conexion();
			ArrayList<String> rs = con.consulta("select raza from raza order by raza ASC");
			
			
			
			for(String x : rs) {
				jComboBox1.addItem(x);
			}
			con.desconectar();
///////////////////////////////////
			
			jComboBox1.setDoubleBuffered(false);
			jComboBox1.setBorder(null);
		}
		return jComboBox1;
	}

	private JComboBox getJComboBox0() {
		if (jComboBox0 == null) {
			jComboBox0 = new JComboBox();
			jComboBox0.setModel(new DefaultComboBoxModel(new Object[] {}));
			///////////////////////////////////
						
			jComboBox0.setEnabled(true);
			jComboBox0.removeAllItems();
			
			conexion con = new conexion();
			ArrayList<String> rs = con.consulta("select * from tipo_mascota");

			for(String x : rs) {
				jComboBox0.addItem(x);
			}
			con.desconectar();
///////////////////////////////////
			jComboBox0.setDoubleBuffered(false);
			jComboBox0.setBorder(null);
		}
		return jComboBox0;
	}

	private JTextField getJTextField0() {
		if (jTextField0 == null) {
			jTextField0 = new JTextField();
		}
		return jTextField0;
	}

	private JLabel getJLabel1() {
		if (jLabel1 == null) {
			jLabel1 = new JLabel();
			jLabel1.setText("Tipo");
		}
		return jLabel1;
	}

	private JLabel getJLabel2() {
		if (jLabel2 == null) {
			jLabel2 = new JLabel();
			jLabel2.setText("Edad");
		}
		return jLabel2;
	}

	private JLabel getJLabel3() {
		if (jLabel3 == null) {
			jLabel3 = new JLabel();
			jLabel3.setText("Raza");
		}
		return jLabel3;
	}

	private JLabel getJLabel0() {
		if (jLabel0 == null) {
			jLabel0 = new JLabel();
			jLabel0.setText("Nombre");
		}
		return jLabel0;
	}

	private static void installLnF() {
		try {
			String lnfClassname = PREFERRED_LOOK_AND_FEEL;
			if (lnfClassname == null)
				lnfClassname = UIManager.getCrossPlatformLookAndFeelClassName();
			UIManager.setLookAndFeel(lnfClassname);
		} catch (Exception e) {
			System.err.println("Cannot install " + PREFERRED_LOOK_AND_FEEL
					+ " on this platform:" + e.getMessage());
		}
	}



	private void jButton0MouseMouseClicked(MouseEvent event) {
		//conexion con = new conexion();
		//con.sentencia("");
		//this.setVisible(false);
		//this.getParent().setVisible(true);
		convertidor conv = new convertidor();
		
		d_amo da = new d_amo();
		da.insertar(amo);
		
		b_mascota bm = new b_mascota();
		bm.setRut(amo.getRut());
		bm.setNombre_mascota(jTextField0.getText());
		bm.setEdad(conv.toInt( jTextField1.getText() ));
		d_mascota dm =  new d_mascota();
		b_respuesta br = dm.insertar(bm);
		
	}

}
